package cn.tedu.collection;/**
 * @Author 金帮嘉诚 @Date 2021-06-21 星期一 15:08
 */
/*本类用于测试LinkedList*/

import java.util.LinkedList;

/**知识点*/
public class TestLinkedlList {
    public static void main(String[] args) {
        LinkedList<String> list=new LinkedList<String>();
        list.add("唐三藏");
        list.add("孙悟空");
        list.add("猪八戒");
        list.add("沙师弟");
        list.add("白龙马");
        System.out.println(list);

        //add addAll remove isEmpty size contains toArray iterator
        System.out.println("list.contains(\"唐三藏\") = " + list.contains("唐三藏"));
        System.out.println("list.indexOf(\"唐三藏\") = " + list.indexOf("唐三藏"));



        //add get remove
        System.out.println();
        list.addFirst("蜘蛛精");
        list.addLast("玉兔精");
        System.out.println("list = " + list);
        System.out.println("list.getFirst() = " + list.getFirst());
        System.out.println("list.getLast() = " + list.getLast());

        System.out.println();
        System.out.println("list.removeFirst() = " + list.removeFirst());
        System.out.println("list.removeLast() = " + list.removeLast());
        System.out.println(list+"\n");

        //element offer peek poll
        LinkedList<String> list2=new LinkedList<String>();
        list2.addLast("西游记");
        list2.addLast("红楼梦");
        list2.addLast("三国演义");
        list2.addLast("水浒传");

        /*别名：查询系列*/
        System.out.println("list2.peek() = " + list2.peek());//==peekFirst
        System.out.println("list2.peekFirst() = " + list2.peekFirst());
        System.out.println("list2.peekLast() = " + list2.peekLast());
        System.out.println(list2+"\n");

        /*别名：新增系列*/
        System.out.println("list2.offer() = " + list2.offer("金瓶梅"));//=offerLast
        System.out.println("list2.offerFirst() = " + list2.offerFirst("聊斋志异"));//
        System.out.println("list2.offerLast(\"儒林外史\") = " + list2.offerLast("儒林外史"));//
        System.out.println(list2+"\n");

        /*别名：删除系列*/
        System.out.println("list2.poll() = " + list2.poll());//==pollFirst
        System.out.println(list2);
        System.out.println("list2.pollFirst() = " + list2.pollFirst());
        System.out.println(list2);
        System.out.println("list2.pollLast() = " + list2.pollLast());
        System.out.println(list2+"\n");

        System.out.println("list2.element() = " + list2.element());//element\getFirst\peek\peekFirst
        System.out.println(list2);

    }
}
